package cn.stylefeng.guns.modular.yingbao.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yingbao.entity.Payee;
import cn.stylefeng.guns.modular.yingbao.model.params.PayeeParam;
import cn.stylefeng.guns.modular.yingbao.service.PayeeService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import me.zhyd.oauth.utils.StringUtils;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 平台收款信息控制器
 *
 * @author zs
 * @Date 2019-12-19 15:16:36
 */
@CrossOrigin
@Api(tags = "平台收款模块")
@Controller
@RequestMapping("/payee")
public class PayeeController extends BaseController {

    private String PREFIX = "/payee";

    @Autowired
    private PayeeService payeeService;

    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2019-12-19
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/payee.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2019-12-19
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/payee_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2019-12-19
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/payee_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2019-12-19
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(PayeeParam payeeParam) {
        this.payeeService.add(payeeParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2019-12-19
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(Integer id,String name,Integer nameid,String pic,String account,String phone,String backup1) {
//        this.payeeService.update(payeeParam);
        Payee byId = this.payeeService.getById(id);
        if(StringUtils.isEmpty(phone) || "".equals(phone)){
            byId.setPhone(null);
        }else {
            byId.setPhone(phone);
        }
        byId.setPic(pic);
        byId.setBackup1(backup1);
        byId.setAccount(account);
        Integer b = this.payeeService.upById(byId);
        if(b > 0){
            return ResponseData.success();
        }
        return ResponseData.error(500,"修改错误");
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2019-12-19
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(PayeeParam payeeParam) {
        this.payeeService.delete(payeeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2019-12-19
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(PayeeParam payeeParam) {
        Payee detail = this.payeeService.getById(payeeParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zs
     * @Date 2019-12-19
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(PayeeParam payeeParam) {
        return this.payeeService.findPageBySpec(payeeParam);
    }

    @PostMapping("queryByNameAndId")
    @ResponseBody
    @ApiOperation("调用相应的付款信息")
    @ApiImplicitParam(name = "id",value = "1,微信.2,支付宝.3,银行卡")
    public ResponseData queryByNameAndId(String id){
        return payeeService.queryByNameAndId(id);
    }

    @PostMapping("queryAll")
    @ResponseBody
    public ResponseData queryAll(){
        List<Payee> list = payeeService.queryAll();
        if(list.size() > 0){
            return ResponseData.success(list);
        }
        return ResponseData.error(500,"暂无平台收款信息");
    }

    @PostMapping("queryAll1")
    @ResponseBody
    public ResponseData queryAll1(){
        List<Payee> list = payeeService.queryAll1();
        if(list != null ||list.size() > 0){
            return ResponseData.success(list);
        }
        return ResponseData.error(500,"暂无平台收款信息");
    }
}


